#include <bits/stdc++.h>
using namespace std;

const int N=1e5+5;
long long T,n,m,L,V,cnt,ans;
long long d[N],v[N],a[N],p[N];
bool A,B,C;
struct way{
    int sd,fd;
    bool operator < (const way &bb) const{
        if (this->sd==bb.sd) return this->fd<bb.fd;
        return this->sd<bb.sd;
    }
} t[N];

int solve(int dist){
    int l=0,r=m+1;
    while (l<r){
        int mid=(l+r)>>1;
        if (p[mid]>=dist){
            r=mid;
        } else {
            l=mid+1;
        }
    }
    return l;
}

bool chs[N];
void dfs(int x){
    if (x>m){
        int ttt=0;
        int flag=0;
        for (int j=1;j<=n;j++){
            for (int i=1;i<=m;i++){
                if (chs[i] && i>=t[j].sd && i<=t[j].fd){
                    flag++;
                    continue;
                }
            }
        }
        if (flag != n) return;
        for (int i=1;i<=m;i++){
            if (chs[i]) ttt++;
        }
        ans=max(m-ttt,ans);
        return;
    }
    chs[x]=0;
    dfs(x+1);
    chs[x]=1;
    dfs(x+1);
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    while (T--){
        cnt=ans=0;
        scanf("%lld %lld %lld %lld", &n, &m, &L, &V);
        for (int i=1;i<=n;i++){
            scanf("%lld %lld %lld", &d[i], &v[i], &a[i]);
            t[i].sd=t[i].fd=0;
        }
        for (int i=1;i<=m;i++){
            scanf("%lld", &p[i]);
        }
        p[0]=-1;
        p[m+1]=L+1;
        for (int i=1;i<=n;i++){
            if (a[i]>0){
                if (v[i]>V && d[i]<=p[m]){
                    cnt++;
                    t[i].sd=solve(d[i]);
                    t[i].fd=m;
                    continue;
                } else if (v[i]>V){
                    continue;
                }
                long long xx=d[i]+(V*V-v[i]*v[i])/2/a[i]+1;
                if (xx-1>=p[m]) continue;
                cnt++;
                t[i].sd=solve(xx);
                t[i].fd=m;
            } else if (a[i]==0){
                if (v[i]<=V || d[i]>p[m]) continue;
                cnt++;
                t[i].sd=solve(d[i]);
                t[i].fd=m;
            } else {
                if (v[i]<=V) continue;
                int tt=solve(d[i]);
                long long xx=d[i]+(v[i]*v[i]-V*V)/(2*abs(a[i]))+1;
                long long tkjt=v[i]*v[i]-V*V,yyoy=2*abs(a[i]);
                if (tkjt%yyoy==0) xx--;
                if (xx<=p[tt]) continue;
                cnt++;
                t[i].sd=tt;
                t[i].fd=solve(xx)-1;
            }
        }
        printf("%lld ", cnt);
        sort(t+1,t+1+n);
        /*
        puts("");
        for (int i=1;i<=n;i++){
            printf("%d %d\n", t[i].sd, t[i].fd);
        }
        puts("");
        */
        if (n<=20 && m<=20){
            dfs(1);
            printf("%lld\n", ans);
        } else {
            int ii=1;
            while (ii<=n){
                if (t[ii].sd==0 && t[ii].fd==0){
                    ii++;
                    continue;
                }
                int jj=t[ii].fd;
                ans++;
                while (jj>=t[ii].sd && ii<=n) ii++;
            }
            printf("%lld\n", m-ans);
        }
    }
    return 0;
}
